package com.wmm.servlet.student;

import com.wmm.bean.Student;
import com.wmm.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "UpdateStudentServlet" ,urlPatterns = "/updateStudent")
public class UpdateStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String studentno = request.getParameter("studentno");
        String method = request.getParameter("method");
        StudentService studentService = new StudentService();
        List<Student> query = studentService.queryStudentServer(studentno, null);
        HttpSession session = request.getSession();
        session.setAttribute("updateStudent",query.get(0));
        response.sendRedirect("update.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
